// 放置 user相关的请求

import type { CHECKPWDFORM, LoginForm, USER, USERForm } from "@/types/user"
import type { RESPONSE } from "@/types/base"

import request from "./request"

// 请求路径统一管理
enum API {
  LOGIN = "/login",
  CHECK_PWD = "/manage/user/pwd",
  CHANGE_PWD = "/manage/user/pwd",
  ADD_USER = "/manage/user/add",
  GET_ALL_USER = "/manage/user/all",
  GET_USER = "/manage/user/list",
  UPDATE_USER = "/manage/user/update",
  DEL_USER = "/manage/user/delete",
}

// 暴漏一个登陆方法
// {
//   status: 0/1
//   msg: '',
//   data: {
//     name
//     username
//   }
// }
export const reqLogin = (loginForm: LoginForm) =>
  request.post<null, RESPONSE<USER>>(API.LOGIN, loginForm)

export const reqCheckPwd = (checkForm: CHECKPWDFORM) => {
  return request.post<null, RESPONSE<USER>>(API.CHECK_PWD, checkForm)
}

export const reqChangePwd = (form: CHECKPWDFORM) =>
  request.put<null, RESPONSE<null>>(API.CHANGE_PWD, form)

export const reqAddUser = (form: USERForm) =>
  request.post<null, RESPONSE<USER>>(API.ADD_USER, form)

export const reqGetAllUser = () =>
  request.get<null, RESPONSE<USER[]>>(API.GET_ALL_USER)

export const reqGETUSER = (data: { page: number; size: number }) =>
  request.post<null, RESPONSE<{ total: number; data: USER[] }>>(
    API.GET_USER,
    data
  )
export const reqUpdateUser = (data: USERForm) =>
  request.post<null, RESPONSE<USER>>(API.UPDATE_USER, data)

export const reqDelUser = (userId: string) =>
  request.post<null, RESPONSE<null>>(API.DEL_USER, { userId })
